clear
%oad ../parameter_sandbox_ces/eq_mit_mass.mat 
%x = load('../free_entry_labor_no_dispersion_frictionless/eq_mit_entry.mat');

x = readtable('../../bgm/translog_irf.csv');
z = readtable('../../bgm/ces_irf.csv');


%%
%load ../parameter_sandbox_wage_rule/eq_mit_mass.mat 
y = load('../free_entry/eq_mit_entry.mat');
%load ../prod/calibration_v3/sandbox/eq_mit_mass.mat
eq_mit = y.eq_mit;
glob   = y.glob;
options = y.options;

%% get actual data - mass of firms

%Ns = [1, 1 - .04];% + [0.0000000 -0.7654149 -4.1384743 -5.6245749 -6.4591448 -5.1005793 -4.2323999]/100;
Ns =  1 - [7.13]/100;

prods = repmat(exp(glob.sf(:,2)), 1, options.T);

% pick scaling coefficients
Labor       =  eq_mit.l;
total_labor =  sum(eq_mit.mu.*Labor);

adj = sum(eq_mit.mu,1);
scx = pick_scale(adj, Ns);

mass = sum(eq_mit.mu,1);
Ns = log_linear_scale(mass, scx)/mass(end);
Ns = Ns(1:50);


%% compute cost-weighted markups
ngdp = sum(eq_mit.mu.*eq_mit.p.*eq_mit.y);
labor_bill = eq_mit.W'.*sum(eq_mit.l.*eq_mit.mu);
labor_share = (labor_bill./ngdp);

%%
set(0,'defaultaxesfontname','cambria math') % beautify the axes a bit
set(0,'defaultTextFontName', 'cambria math')


close all

T = 15;
subplot(2,3,1)
mass = sum(eq_mit.mu,1);
plot(log_linear_scale_plot(mass, scx), 'LineWidth', 4); xlim([1 T]); title('Mass of producers')
ytickformat('percentage')

hold on
plot(x.Var1, 'r-.', 'LineWidth', 4);
plot(z.Var1, '--', 'LineWidth', 4); 
yline(0, '--')

%plot(Ns, 'LineWidth', 4)
legend('Baseline', 'Symmetric Translog','Symmetric CES', '', 'Location', 'Southeast')

subplot(2,3,5)
plot(log_linear_scale_plot(eq_mit.C, scx), 'LineWidth', 4); xlim([1 T]);  title('Output')
hold on
plot(x.Var5, 'r-.', 'LineWidth', 4); xlim([1 T]);  title('Output')
plot(z.Var5, '--', 'LineWidth', 4); xlim([1 T]);  title('Output')
ytickformat('percentage')
yline(0, '--')

subplot(2,3,6)
plot(log_linear_scale_plot(eq_mit.W, scx), 'LineWidth', 4); xlim([1 T]);  title('Wage')
hold on
plot(x.Var6,  'r-.', 'LineWidth', 4)
plot(z.Var6,  '--', 'LineWidth', 4)
ytickformat('percentage')
yline(0, '--')

subplot(2,3,4)
plot(log_linear_scale_plot(eq_mit.L, scx), 'LineWidth', 4); xlim([1 T]); title('Employment')
hold on
plot(x.Var4, 'r-.', 'LineWidth', 4); xlim([1 T]); title('Employment')
plot(z.Var4, '--', 'LineWidth', 4); xlim([1 T]); title('Employment')
ytickformat('percentage')
yline(0, '--')

labor_share = 1./labor_share;

 subplot(2,3,2)
 plot((log_linear_scale_plot(labor_share, scx)), 'LineWidth', 4); xlim([1 T]); title('Markup')
 hold on
plot(x.Var2, 'r-.', 'LineWidth', 4); xlim([1 T]); title('Markup')
plot(z.Var2, '--', 'LineWidth', 4); xlim([1 T]); title('Markup')
ytickformat('percentage')
yline(0, '--')

subplot(2,3,3)

Ys    = repmat(eq_mit.C',glob.Nsf,1);
Z     = sum(eq_mit.y./Ys./prods.*eq_mit.mu);
tfp   = log_linear_scale(Z.^(-1), scx);



plot(100*(tfp/tfp(end)-1), 'LineWidth', 4); xlim([1 T]);
hold on
plot(x.Var3,  'r-.', 'LineWidth', 4); 
plot(z.Var3,  '--', 'LineWidth', 4); 
xlim([1 T]);
ytickformat('percentage')
yline(0, '--')

title('Effective TFP')
set(gcf,'units','points','position',[10,10,1000,600])
set(findall(gcf,'-property','FontSize'),'FontSize',16)

print('-dpng', 'figures/baseline_vs_bgm.png')



